package com.mf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mf.entity.bo.FamilyInfoBo;
import com.mf.entity.vo.FamilyInfoVo;
import com.mf.mapper.FamilyInfoMapper;
import com.mf.service.IFamilyInfoService;
import io.github.heollhai.common.utils.MybatisPlusUtils;
import io.github.heollhai.common.utils.VerifyUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务实现类
 *
 * @author mf
 * @since 2024-09-01
 */
@Service
public class FamilyInfoServiceImpl extends ServiceImpl<FamilyInfoMapper, FamilyInfoBo> implements IFamilyInfoService {
    @Resource
    private FamilyInfoMapper familyInfoMapper;


    /**
     * 查询
     */
    @Override
    public List<FamilyInfoVo> selectByRosterId(Integer rosterId) {
        final LambdaQueryWrapper<FamilyInfoBo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FamilyInfoBo::getRosterId, rosterId);
        return MybatisPlusUtils.changeDataClass(familyInfoMapper.selectList(queryWrapper), FamilyInfoVo.class);
    }

    /**
     * 新增
     */
    @Override
    public Integer insert(FamilyInfoVo familyInfoVo) {
        final FamilyInfoBo familyInfoBo = new FamilyInfoBo();
        BeanUtils.copyProperties(familyInfoVo, familyInfoBo);
        if (VerifyUtils.isEmpty(familyInfoVo.getId())) {
            return familyInfoMapper.insert(familyInfoBo);
        } else {
            return familyInfoMapper.updateById(familyInfoBo);
        }
    }
}
